package pers.qianyu.diytomcat.catalina;

import cn.hutool.core.date.*;
import cn.hutool.log.*;
import pers.qianyu.diytomcat.util.*;

import java.util.*;

/**
 * @author mizzle rain
 * @date 2021-01-07 16:52
 */
public class Service {
    private String name;
    private Engine engine;
    private Server server;
    private List<Connector> connectors;

    public Service(Server server) {
        this.name = ServerXmlUtil.getServiceName();
        this.engine = new Engine(this);
        this.server = server;
        this.connectors = ServerXmlUtil.getConnectors(this);
    }

    public void start() {
        init();
    }

    private void init() {
        TimeInterval timer = DateUtil.timer();
        connectors.forEach(Connector::init);
        LogFactory.get().info("Initialization processed in {} ms", timer.intervalMs());
        connectors.forEach(Connector::start);
    }

    /************** automatic generated *****************/
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Engine getEngine() {
        return engine;
    }

    public void setEngine(Engine engine) {
        this.engine = engine;
    }

    public Server getServer() {
        return server;
    }

    public void setServer(Server server) {
        this.server = server;
    }

    public List<Connector> getConnectors() {
        return connectors;
    }

    public void setConnectors(List<Connector> connectors) {
        this.connectors = connectors;
    }
}
